<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace app\shop\api;

use app\common\api\BaseApi;
use app\shop\model\ProductMemberPrice;
use app\system\api\UserMemberApi;
// use app\extend\Page;

class ProductMemberPriceApi extends BaseApi{

		const ADD              = "shop/ProductMemberPriceApi/add";
		const DELETE           = "shop/ProductMemberPriceApi/delete";
		const SAVE             = "shop/ProductMemberPriceApi/save";
		const SAVE_BY_ID       = "shop/ProductMemberPriceApi/saveByID";
		const COUNT            = "shop/ProductMemberPriceApi/count";
		const GET_INFO         = "shop/ProductMemberPriceApi/getInfo";
		const QUERY            = "shop/ProductMemberPriceApi/query";
		const QUERY_NO_PAGING  = "shop/ProductMemberPriceApi/queryNoPaging";
		const QUERY_WITH_COUNT = "shop/ProductMemberPriceApi/queryWithCount";
		const GET_INFO_BY_SKUID = "shop/ProductMemberPriceApi/getInfoBySkuID";

    protected function _init(){
        $this -> model = new ProductMemberPrice();
    }

    public function getInfoBySkuID($uid = '',$skuid = '',$field= false){
    	$uid = intval($uid);
    	if(!$uid) return $this->apiReturnErr('uid错误');
    	$r   = apiCall(UserMemberApi::GET_INFO,[['uid'=>$uid],false,'group_id,active_status']);
    	if(!$r['status']) return $this->apiReturnErr($r['info']);
    	if(empty($r['info'])) return $this->apiReturnErr('未发现用户会员组');
    	$group_id = intval($r['info']['group_id']);
    	if(0 === intval($r['info']['active_status']) && 2 === $group_id){
    		$group_id = 1;
    	}
    	$r = $this->getInfo(['member_group_id'=>$group_id,'sku_id'=>$skuid],false,$field);
    	if(false === $r['status']) return $this->apiReturnErr($r['info']);
    	return $this->apiReturnSuc($r['info']);
    }
}